// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.audio.parameters;

import fmod.fmod.FMODSoundEmitter;
import zombie.audio.FMODLocalParameter;
import zombie.characters.IsoPlayer;
import zombie.core.math.PZMath;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoWorld;

public final class ParameterOcclusion extends FMODLocalParameter {
    private final FMODSoundEmitter emitter;
    private float currentValue = Float.NaN;

    public ParameterOcclusion(FMODSoundEmitter fMODSoundEmitter) {
        super("Occlusion");
        this.emitter = fMODSoundEmitter;
    }

    @Override
    public float calculateCurrentValue() {
        float float0 = 1.0F;

        for (int _int = 0; _int < 4; _int++) {
            float float1 = this.calculateValueForPlayer(_int);
            float0 = PZMath.min(float0, float1);
        }

        this.currentValue = float0;
        return (float)((int)(this.currentValue * 1000.0F)) / 1000.0F;
    }

    @Override
    public void resetToDefault() {
        this.currentValue = Float.NaN;
    }

    private float calculateValueForPlayer(int _int) {
        IsoPlayer isoPlayer = IsoPlayer.players[_int];
        if (isoPlayer == null) {
            return 1.0F;
        } else {
            IsoGridSquare isoGridSquare0 = isoPlayer.getCurrentSquare();
            IsoGridSquare isoGridSquare1 = IsoWorld.instance.getCell().getGridSquare((double)this.emitter.x, (double)this.emitter.y, (double)this.emitter.z);
            if (isoGridSquare1 == null) {
                boolean _boolean = true;
            }

            float _float = 0.0F;
            if (isoGridSquare0 != null && isoGridSquare1 != null && !isoGridSquare1.isCouldSee(_int)) {
                _float = 1.0F;
            }

            return _float;
        }
    }
}
